package _18_剑指OfferII;

import java.util.Arrays;

public class _104_剑指OfferII排列的数目 {

    public static void main(String[] args) {

        _104_剑指OfferII排列的数目 v = new _104_剑指OfferII排列的数目();


        int[] ins = {1, 2, 3};
        System.out.println(v.combinationSum4(ins, 4));

    }

    public int combinationSum4(int[] nums, int target) {
        int[] dp = new int[target + 1];
        Arrays.sort(nums);
        dp[0] = 1;

        for (int i = 1; i <= target; ++i) {
            for (int num : nums) {
                if (num > i) break;
                dp[i] += dp[i - num];
            }
        }
        return dp[target];
    }

}
